<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ include file="../header.jsp" %>

    <script type="text/javascript">
    function changePage() {
        $("#pagerForm").submit();
    }

    function cambiarPagina(pageOffset) {
        pageOffset = pageOffset >= 0 ? pageOffset : 0;
        $("#offset").val(pageOffset)
        changePage();
        return false
    }
    </script>


	</head>
      <body>
        <div class="container">
        <div class="main-panel">
        <div class="panel panel-default">
        <div class="panel-heading">
            <h2>Tipos de Documento</h2>
            <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/tiposDeDocumento/agregar" >
                <span class="glyphicon glyphicon-plus"></span> Agregar
            </a>
        </div>
        <div class="panel-body">
        
   	<!-- BEGIN: flash messages -->
    <c:if test="${!sessionScope.hasErrors && sessionScope.successMessage != null}">
    	<div class="alert alert-success"><c:out value="${sessionScope.successMessage}" /></div> 
    </c:if>
    <c:if test="${sessionScope.hasErrors}">
    	<c:forEach items="${sessionScope.errorMessages}" var="message">
    	<div class="alert alert-danger"><c:out value="${message}" /></div>
    	</c:forEach> 
    </c:if>
    <% 
    	session.setAttribute("hasErrors", null);
    	session.setAttribute("successMessage", null);
    	session.setAttribute("errorMessages", null);
    %>
    <!-- END: flash messages -->

		<c:if test="${items != null && pager != null && pager.totalItems > 0}">

        <table class="table table-hover">
            <thead>
                <tr>
                  <th>Nombre</th>
                  <th style="text-align: center;">Es Purgable</th>
                  <th style="text-align: center;">Tiene vencimiento</th>
                </tr>
            </thead>
            <tbody>
            <c:forEach items="${items}" var="documentTypeInstance">
                <tr>
                    <td><a href="${pageContext.request.contextPath}/tiposDeDocumento/editar?id=${documentTypeInstance.id}">${documentTypeInstance.name}</a></td>
                    <td style="text-align: center;"><c:out value="${documentTypeInstance.purgeable ? 'Sí' : 'No'}" /></td>
                    <td style="text-align: center;"><c:out value="${documentTypeInstance.hasExpiration ? 'Sí' : 'No'}" /></td>
                </tr>
            </c:forEach>
            </tbody>
        </table>

        <form id="pagerForm" method="GET">
            <input type="hidden" id="offset" name="offset" />
        </form>

            <input type="hidden" id="offset" name="offset" value="${offset}" />
            
            <jsp:include page="../pagination.jsp" >
    			<jsp:param name="pager" value="${pager}" />
    			<jsp:param name="changeOffsetFunction" value="cambiarPagina" />
			</jsp:include>

			</c:if>
            <c:if test="${pager != null && pager.totalItems == 0}">
                <div class="alert alert-warning">
                No se encontraron resultados
                </div>
            </c:if>


        </div>
        </div>
        </div>
        </div>
      </body>
</html>